﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Data;
using System.Globalization;

namespace BadHabit.WPFTools.Converters {
    
    [ValueConversion(typeof(object), typeof(int))]
    public class NumericCompareConverter : IValueConverter {

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
            if (value == null)
                return -1;
            Double dvalue;
            try {
                dvalue = Double.Parse(value.ToString());
            } catch (Exception) { return -1; }

            return dvalue.CompareTo(parameter);                
        }
            
        
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
            return new NotSupportedException();
        } 
    }
}
